package mytest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.StringTokenizer;

public class PrintTree {

	/**
	 * Build a tree from a stream of edges 。
Write a Java function, printTree(), which prints a given tree to stdout.  
Details:The argument of printTree is a stream of pairs of string values.Each string found anywhere in the input represents a unique node.Each item in the stream is a pair indicating a parent/child relationship in the tree.  The first element in the pair is the parent.  The second element in the pair is the child.Each parent can have many children.The input list may contain relationship pairs in any order, although:The order in which the pairs appear in the input list determines the nodes’ order with respect to its siblings.

	 */
	
	static void print(int root,String pre)
	{
		
		System.out.println(pre+root);
		List<Integer> list=smap.get(root);
		if(list==null)return;
		for(int a:list)print(a,pre+" ");
	}
	
	static HashMap<Integer, List<Integer>> smap=new HashMap<Integer, List<Integer>>();
	//static HashMap<Integer,Integer> pmap=new HashMap<Integer, Integer>();
	/**
	 * @param args
	 */
	public static void main(String[] args)throws Exception {

		Integer root=null;
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=null;
		while((line=bf.readLine())!=null)
		{
			StringTokenizer st=new StringTokenizer(line);
			int p=Integer.parseInt(st.nextToken());
			int s=Integer.parseInt(st.nextToken());
			if(p==0&&s==0)break;
			
			if(!smap.containsKey(p))
			{
				smap.put(p, new ArrayList<Integer>());
			}
			
			if(!smap.containsKey(s))
			{
				smap.put(s, new ArrayList<Integer>());
			}
			
			List<Integer> list=smap.get(p);
			list.add(s);
		}
		//find root
		HashSet<Integer> set=new HashSet<Integer>();
		
		for(Integer s:smap.keySet())set.add(s);
		for(List<Integer> list:smap.values())
		{
			for(Integer s:list){
				if(!set.contains(s))
				{
					System.out.println("error");
					return;
				}
				set.remove(s);
			}
		}
		
		if(set.size()!=1){
			System.out.println("error");
			return;
		}
		
		root=set.iterator().next();
		//print tree
		print(root, "");
	}

}
